<?php if (!defined("BASEPATH")) exit("No direct script access allowed"); ?>

<script type="text/javascript">
	Ext.onReady(function() {

		var winLogs; // edit ablak
		var logsForm; // form panel

		var store = new Ext.data.JsonStore({
			totalProperty: 'total', 
			root: 'results',
			sortInfo: {field: 'logDate', direction: 'DESC'},
			remoteSort: true,
			proxy : new Ext.data.HttpProxy({
				url: '<?=site_url()?>admin/get_logs',
				method: 'GET'
			}),
			fields: [
				{name: 'logId'},
				{name: 'logUsrId'},
				{name: 'logRecId'},
				{name: 'logTable'},
				{name: 'logType'},
				{name: 'logDate'},
				{name: 'logChanges'}
			]
		});

		var grid = new Ext.grid.GridPanel({
			store: store,
			id: 'logGrid',
			viewConfig:{
				emptyText: '<?=$this->db->escape_str($this->lang->line("THERE_IS_CURRENTLY_NO_DATA_TO_DISPLAY"))?>'
			},
			columns: [
				{header: '<?=$this->db->escape_str($this->lang->line("ID"))?>', width: 50, sortable: true, dataIndex: 'logId'},
				{header: '<?=$this->db->escape_str($this->lang->line("USERID"))?>', width: 50, sortable: true, dataIndex: 'logUsrId'},
				{header: '<?=$this->db->escape_str($this->lang->line("RECORDID"))?>', width: 100, sortable: true, dataIndex: 'logRecId'},
				{header: '<?=$this->db->escape_str($this->lang->line("TABLE"))?>', width: 150, sortable: true, dataIndex: 'logTable'},
				{header: '<?=$this->db->escape_str($this->lang->line("TYPE"))?>', width: 50, sortable: true, dataIndex: 'logType'},
				{header: '<?=$this->db->escape_str($this->lang->line("DATE"))?>', width: 150, sortable: true, dataIndex: 'logDate'},
				{id: 'logChanges', header: '<?=$this->db->escape_str($this->lang->line("CHANGES"))?>', width: 150, sortable: false, dataIndex: 'logChanges'}
			],
			autoExpandColumn: 'logChanges',
			stripeRows: true,
			autoHeight: true,
			autoWidth: true,
			sm: new Ext.grid.RowSelectionModel({singleSelect:true}),

			viewConfig: {
				getRowClass: function(record, index) {
					var type = record.get('logType');
					switch(type) {
						case 'INS': return 'grid_ins'; break;
						//case 'UPD': return 'grid_upd'; break;
						case 'DEL': return 'grid_del'; break;
					}
				}
			},

			tbar: {
				items: [
					]
			},

			border: false,

			frame:false,

			plugins:[
				new Ext.ux.grid.Search({
					minChars:2,
					iconCls: 'icon-zoom',
					searchText:'<?=$this->db->escape_str($this->lang->line("SEARCH"))?>',
					position:'top',
					minCharsTipText:'<?=$this->db->escape_str($this->lang->line("MINIMUM_TWO_CHARACTERS_IS_REQUIRED"))?>',
					selectAllText: '<?=$this->db->escape_str($this->lang->line("SELECT_ALL"))?>',
					width:200,
					disableIndexes:[],
					autoFocus:true
				})],

			bbar: new Ext.PagingToolbar({
				pageSize: <?=$this->config->item("adminGridPageSize")?>,
				store: store,
				displayInfo: true,

				plugins: new Ext.ux.ProgressBarPager()
			})

		});

		grid.render('grid-table-logs');

		grid.getSelectionModel().on('selectionchange', function(sm){
			
		});

		store.load({params:{start:0, limit:<?=$this->config->item("adminGridPageSize")?>}});

	})
</script>


<div id="grid-table-logs"></div>